<?php
/**
 * Created by PhpStorm.
 * User: 17208
 * Date: 2019/7/1
 * Time: 10:58
 */

namespace app\api\timer;
use app\common\lib\Redis;
use think\Exception;

class Base
{
    private $lock = "lock";
    private $time = 60;
    public function __construct($lock,$time)
    {
        $this->lock = $lock;
        $this->time = $time;
    }
    /** 获取锁 */
    protected function get_lock(){
        $lock = Redis::get($this->lock);
        if($lock){
            throw new Exception("脚本正在运行");
        }
        Redis::set($this->lock,1,$this->time);
    }
    /** 释放锁 */
    protected function unset_lock(){
        Redis::rm($this->lock);
    }
}